<!-- 
	퀘스트
 -->
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="java.util.*" %>
<%@ page import="model.*" %>
<%
	String listName = "questList";
	ArrayList<Quest> boardList = new ArrayList<Quest>();
	if(request.getAttribute("questList") != null)
		boardList = (ArrayList<Quest>)request.getAttribute(listName);
	int studyId = ((Integer)request.getAttribute("studyId")).intValue();
	String checkValue =  (String)request.getAttribute("checkValue");
	if(checkValue==null){
		%>
		<script>
			location.href= "List.Quest?studyId=<%=studyId %>";
		</script>
		<%
	}
	
	ArrayList<Answer> ansList = (ArrayList<Answer>)request.getAttribute("answerList");
	
	
%>
<section>
	<div class="col-md-6 col-md-offset-3 col-lg-6 col-lg-offset-3">
		<form method="post" action="New.Quest?studyId=<%=studyId%>">
			<button class="btn btn-default" type="submit">퀘스트 생성</button>
		</form>
		<ul class="list-group">
			<%for(Quest quest: boardList) { %>
				<li class="list-group-item">
					<div class="row" onclick="showContent('<%=quest.getQuestId()%>')"><!-- 퀘스트의 제목과 작성자 표시 -->
						<div class="col-xs-4 col-md-3">
							<%=quest.getTitle() %>
						</div>
						<div class="col-xs-8 col-md-9">
							<%=quest.getMemid() %>
						</div>
					</div>
					<div class="panel panel-default" id='<%= quest.getQuestId() %>' style="display:none;"><!-- 퀘스트의 상세내역 표시 -->
						<div class="overflow-block panel-heading">
							<div class="left-block">
								제목 : <%=quest.getTitle() %>
							</div>
							<div class="right-block">
								작성자 : <%=quest.getMemid() %>
							</div>
						</div>
						<div class="panel-body">
							<p><%=quest.getContent() %></p>
						</div>
						<div class="overflow-block panel-footer">
							<div class="left-block">
								시작시간 : <%=quest.getCreatedTime() %>
							</div>
							<div class="right-block">
								마감기한 : <%=quest.getExpiredTime() %>
							</div>
						</div>
						<% if(quest.getMemid().equals(session.getAttribute("memid"))) { %>
						<button type="button" class="btn btn-default" onclick="modify('quest', '<%=studyId %>', '<%=quest.getQuestId() %>')">수정</button>
						<% } %>
						<%if(!quest.isExpired()) { %>
						<button type="button" class="btn btn-default" onclick="doQuest('<%=studyId%>','<%=quest.getQuestId()%>')">퀘스트하기</button>
						<%} %>
						<ul class="list-group">
						<%for(Answer ans : ansList) {
							if(ans.getQid() == quest.getQuestId()) { %>
								<li class="list-group-item" onclick="showAnswer('<%=studyId%>','<%=quest.getQuestId()%>','<%=ans.getAnswerId()%>')"><%=ans.getMemid() %></li>
						<%}} %>
						</ul>
					</div>
				</li>
			<%} %>
		</ul>
	</div>
</section>